package com.eduction.resource;

import java.sql.SQLException;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.eduction.bean.SchoolBean;
import com.eduction.common.MessageContants;
import com.eduction.common.ResultBean;
import com.eduction.common.Sequence;
import com.eduction.service.ILoginService;

@RestController
@RequestMapping("/school")
public class SchoolResource extends BaseController{
	@Autowired
	private ILoginService loginService;
	@RequestMapping(value="/login")
	public ResultBean login(HttpServletRequest request) {
		ResultBean resultBean = new ResultBean();
		String id = request.getParameter("schoolId");
		String pass = request.getParameter("password");
		try {
			 SchoolBean  scb = loginService.getSchoo(id,pass);
			 if(null == scb){
				 resultBean.setCode(ResultBean.ERRORCODE);
				 resultBean.setMessage(MessageContants.PASSWORD_ERROR);
			 }else{
				 resultBean.setCode(ResultBean.SUCCESSCODE);
				 resultBean.setMessage(MessageContants.LOGIN_SUCCESS);
				 resultBean.setData(scb);
				 request.getSession().setAttribute("school", scb);
			 }
		} catch (SQLException e) {
			resultBean.setCode(ResultBean.ERRORCODE);
			resultBean.setMessage(MessageContants.SERVER_ERROR);
		}
		return resultBean;
	}
	
}
